package com.zhiwei.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhiwei.mapper.RightsMapper;
import com.zhiwei.pojo.Rights;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RightsServiceImpl implements RightsService{
    @Autowired
    private RightsMapper rightsMapper;

    @Override
    public List<Rights> getRightsList() {
        Rights rights = new Rights();
        rights.setParentId(0);
        List<Rights> list = rightsMapper.selectList(new QueryWrapper<>(rights));
        for (Rights parent : list) {
            QueryWrapper<Rights> wrapper = new QueryWrapper<>();
            wrapper.eq("parent_id", parent.getId());
            List<Rights> children = rightsMapper.selectList(wrapper);
            parent.setChildren(children);
        }
        return list;
    }
}
